<?php

/**
 * This is the model class for table "user_logs".
 *
 * The followings are the available columns in table 'user_logs':
 * @property integer $id
 * @property integer $user_id
 * @property string $name
 * @property string $email
 * @property string $subject
 * @property string $message
 * @property string $company_name
 * @property integer $sender_agent
 * @property string $sender_ip
 * @property integer $sender_os
 * @property string $sent_at
 *
 * The followings are the available model relations:
 * @property Users $user
 */
class UserLogs extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return UserLogs the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user_logs';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id, user_id, name, email, subject, message, company_name, sender_agent, sender_ip, sender_os, sent_at', 'required'),
			array('id, user_id, sender_agent, sender_os', 'numerical', 'integerOnly'=>true),
			array('name, email, subject, company_name, sent_at', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, user_id, name, email, subject, message, company_name, sender_agent, sender_ip, sender_os, sent_at', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'user_id' => 'User',
			'name' => 'Name',
			'email' => 'Email',
			'subject' => 'Subject',
			'message' => 'Message',
			'company_name' => 'Company Name',
			'sender_agent' => 'Sender Agent',
			'sender_ip' => 'Sender Ip',
			'sender_os' => 'Sender Os',
			'sent_at' => 'Sent At',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('subject',$this->subject,true);
		$criteria->compare('message',$this->message,true);
		$criteria->compare('company_name',$this->company_name,true);
		$criteria->compare('sender_agent',$this->sender_agent);
		$criteria->compare('sender_ip',$this->sender_ip,true);
		$criteria->compare('sender_os',$this->sender_os);
		$criteria->compare('sent_at',$this->sent_at,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}